
const { createWebAPIRequest } = require('../../util/util')

module.exports =
module.exports = [
  {
    /**
    * @api {get} /music/search [搜索]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {String} keywords 关键词
    * @apiParam {Number} [type=1] 搜索单曲(1)，歌手(100)，专辑(10)，歌单(1000)，用户(1002)
    * @apiParam {Number} [limit=20] 每页数量
    * @apiParam {Number} [offset=0] 页码
    */
    url: '/music/search',
    method: 'get',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const keywords = req.query.keywords
      const type = req.query.type || 1
      const limit = req.query.limit || 20
      const offset = req.query.offset || 0
      // *(type)* 搜索单曲(1)，歌手(100)，专辑(10)，歌单(1000)，用户(1002)
      const data = {
        csrf_token: '',
        limit,
        type,
        s: keywords,
        offset
      }

      createWebAPIRequest(
        'music.163.com',
        '/weapi/search/get',
        'POST',
        data,
        cookie,
        musicReq => res.send(musicReq),
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/search/multimatch [搜索 multimatch]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {String} keywords 关键词
    * @apiParam {Number} [offset=0] 页
    * @apiParam {Number} [limit=20]  每页数量
    * @apiParam {Number} [type=1] 搜索单曲(1)，歌手(100)，专辑(10)，歌单(1000)，用户(1002)
    */
    url: '/music/search/multimatch',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const limit = req.query.limit || 20
      const offset = req.query.offset || 0
      const data = {
        csrf_token: '',
        type: req.query.type || 1,
        s: req.query.keywords || '',
        limit,
        offset
      }

      createWebAPIRequest(
        'music.163.com',
        '/weapi/search/suggest/multimatch',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }, {
    /**
    * @api {get} /music/search/suggest [搜索 suggest]
    * @apiGroup Music
    * @apiPermission none
    * @apiDescription 搜索结果包含单曲,歌手,歌单,mv信息
    * @apiParam {String} keywords 关键词
    */
    url: '/music/search/suggest',
    request: (req, res) => {
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''
      const data = {
        csrf_token: '',
        s: req.query.keywords || ''
      }

      createWebAPIRequest(
        'music.163.com',
        '/weapi/search/suggest/web',
        'POST',
        data,
        cookie,
        musicReq => {
          res.send(musicReq)
        },
        err => res.status(500).send({err})
      )
    }
  }
]
